<?php
/**
 * Created by PhpStorm.
 * User: Auser
 * Date: 2017/7/13
 * Time: 22:46
 */

namespace App\Http\Helper;

class BeanHelper
{

    /**
     * 将标准来转化为数组
     * @param $stdCls
     * @return mixed
     */
    public static function convertStdClsToArr($stdCls){
        return json_decode(json_encode($stdCls),true);
    }


    /**
     * 转化时间类型的数为图表数据
     * @param $timeLabel
     * @param $dataList
     * @param string $timeKey
     * @param string $countDataKey
     * @return array
     */
    public static function convertChartData($timeLabel,$dataList,$timeKey ='day_index',$countDataKey = 'total'){
        if($dataList){
            $logObj = [];
            foreach ($dataList as $log){
                $logObj[$log[$timeKey]] = $log[$countDataKey];
            }
        }
        //日期的格式话
        foreach ($timeLabel as $mDay){
            if(isset($logObj[$mDay])){
                //统计数据量
                $count = $logObj[$mDay];
            }else{
                $count =  0;
            }
            $chartData[$mDay] = $count;
        }
        return [
            'label' => array_keys($chartData),
            'data' => array_values($chartData),
        ];
    }

}